package com.miyake.client.profile;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public abstract class ThumbNail extends Composite {
	private int columns;
	private int totalCount;
	private VerticalPanel verticalPanel;
	public ThumbNail(int totalCount, int columns) {
		this.columns = columns;
		this.totalCount = totalCount;
		this.verticalPanel = new VerticalPanel();
		initWidget(verticalPanel);
	}

	public void show() {
		Grid grid = new Grid(1, columns);
		int rows = (totalCount + columns - 1) / columns;
		
		grid.resize(rows, columns);
		for (int row = 0; row < rows; row++) {
			for (int col = 0; col < columns; col++) {
					if (col + row < totalCount) {
						grid.setWidget(row, col, getWidget(row+col));
					}
			}
		}
		verticalPanel.add(grid);
		grid.setWidth("100%");

	}

	abstract protected Widget getWidget(int i);
}
